﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChallengePuzzle.Lib
{
    /// <summary>
    /// 数组累加器
    /// </summary>
    public class PlusSum1 : ChallengePuzzle.Lib.IPlusSum
    {
        int PreValue = 0;

        public int GetPlusSum(int Number)
        {
            int LessNum = Number % 10;

            if (LessNum != 0)
            {
                PreValue++;

                SumDC.Add(Number, PreValue);
                //SumDC[Number] = PreValue;
                return PreValue;
            }

            PreValue = GetPlusSum1(Number);

            return PreValue;


        }


        private Dictionary<int, int> SumDC = new Dictionary<int, int>();
        //private int[] SumDC = new int[1000000000];
        //--------------------------------------------------------------------------


        public int GetPlusSum1(int Number)
        {
            int DivNum = Number / 10;

            int LessNum = DivNum % 10;

            if (LessNum != 0) return SumDC[DivNum];

            if (DivNum < 10) return DivNum;

            return GetPlusSum1(DivNum);
        }






    }
}
